package com.dianping.cat.consumer.top.model.transform;

import com.dianping.cat.consumer.top.model.IEntity;
import com.dianping.cat.consumer.top.model.IVisitor;
import com.dianping.cat.consumer.top.model.entity.Domain;
import com.dianping.cat.consumer.top.model.entity.Error;
import com.dianping.cat.consumer.top.model.entity.Machine;
import com.dianping.cat.consumer.top.model.entity.Segment;
import com.dianping.cat.consumer.top.model.entity.TopReport;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  15 */   private Stack<Object> m_objs = new Stack();

  private TopReport m_topReport;


  public DefaultMerger() {}

  public DefaultMerger(TopReport topReport) {
/*  23 */     this.m_topReport = topReport;
    this.m_objs.push(topReport);
  }


/*  28 */   public TopReport getTopReport() { return this.m_topReport; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
    this.m_objs.push(to);
/*  37 */     from.accept(this);
/*  38 */     this.m_objs.pop();
  }


/*  42 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  46 */   protected void mergeError(Error to, Error from) { to.mergeAttributes(from); }



/*  50 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }



/*  54 */   protected void mergeSegment(Segment to, Segment from) { to.mergeAttributes(from); }



/*  58 */   protected void mergeTopReport(TopReport to, TopReport from) { to.mergeAttributes(from); }



  public void visitDomain(Domain from) {
/*  63 */     Domain to = (Domain)this.m_objs.peek();

/*  65 */     mergeDomain(to, from);
/*  66 */     visitDomainChildren(to, from);
  }

  protected void visitDomainChildren(Domain to, Domain from) {
/*  70 */     for (Segment source : from.getSegments().values()) {
/*  71 */       Segment target = to.findSegment(source.getId());

/*  73 */       if (target == null) {
/*  74 */         target = new Segment(source.getId());
/*  75 */         to.addSegment(target);
      }

      this.m_objs.push(target);
/*  79 */       source.accept(this);
/*  80 */       this.m_objs.pop();
    }
  }


  public void visitError(Error from) {
/*  86 */     Error to = (Error)this.m_objs.peek();

/*  88 */     mergeError(to, from);
/*  89 */     visitErrorChildren(to, from);
  }


  protected void visitErrorChildren(Error to, Error from) {}


  public void visitMachine(Machine from) {
/*  97 */     Machine to = (Machine)this.m_objs.peek();

/*  99 */     mergeMachine(to, from);
/* 100 */     visitMachineChildren(to, from);
  }


  protected void visitMachineChildren(Machine to, Machine from) {}


  public void visitSegment(Segment from) {
/* 108 */     Segment to = (Segment)this.m_objs.peek();

/* 110 */     mergeSegment(to, from);
/* 111 */     visitSegmentChildren(to, from);
  }

  protected void visitSegmentChildren(Segment to, Segment from) {
/* 115 */     for (Error source : from.getErrors().values()) {
/* 116 */       Error target = to.findError(source.getId());

/* 118 */       if (target == null) {
/* 119 */         target = new Error(source.getId());
/* 120 */         to.addError(target);
      }

/* 123 */       this.m_objs.push(target);
/* 124 */       source.accept(this);
/* 125 */       this.m_objs.pop();
    }

/* 128 */     for (Machine source : from.getMachines().values()) {
/* 129 */       Machine target = to.findMachine(source.getId());

/* 131 */       if (target == null) {
/* 132 */         target = new Machine(source.getId());
/* 133 */         to.addMachine(target);
      }

/* 136 */       this.m_objs.push(target);
/* 137 */       source.accept(this);
/* 138 */       this.m_objs.pop();
    }
  }


  public void visitTopReport(TopReport from) {
/* 144 */     TopReport to = (TopReport)this.m_objs.peek();

/* 146 */     mergeTopReport(to, from);
/* 147 */     visitTopReportChildren(to, from);
  }

  protected void visitTopReportChildren(TopReport to, TopReport from) {
/* 151 */     for (Domain source : from.getDomains().values()) {
/* 152 */       Domain target = to.findDomain(source.getName());

/* 154 */       if (target == null) {
/* 155 */         target = new Domain(source.getName());
/* 156 */         to.addDomain(target);
      }

/* 159 */       this.m_objs.push(target);
/* 160 */       source.accept(this);
/* 161 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/top/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */